/**
 * My simple header template from child directory
 * NIOCalculator.java - ${projectName} - ${organizationName} - ${inceptionYear}
 */

import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;

/**
 * Created with IntelliJ IDEA.
 * User: Gauss
 * Date: 04.03.14
 * Time: 21:18
 * To change this template use File | Settings | File Templates.
 */
public class NIOCalculator extends SimpleFileVisitor<Path> implements FileSizeCalculator {

    private long size;

    @Override
    public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
        size =  size + attrs.size();
        return FileVisitResult.CONTINUE;
    }

    public long calculateSize(String fileName) throws IOException {
        size = 0;
        Path startPath = Paths.get(fileName);
        Files.walkFileTree(startPath, this);
        return size;
    }

    @Override
    public String getName() {
        return "NIOCalculator";
    }
}
